#include <iostream>
#include <pthread.h>

void *thfunc(void *arg)
{
    std::cout << "sub thread is running" << std::endl;
    return NULL;
}

int main()
{
    pthread_t tid;
    pthread_attr_t thread_attr;
    struct sched_param thread_param;
    size_t stack_size;
    int res;

    res = pthread_attr_init(&thread_attr);
    if (res)
    {
        std::cout << "init failed" << std::endl;
    }
    res = pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);

    if (res)
    {
        std::cout << "set detachstate failed" << std::endl;
    }

    res = pthread_create(&tid, &thread_attr, thfunc, NULL);

    if (res)
    {
        std::cout << "pthread creat failed " << std::endl;
    }

    std::cout << "main thread will exit" << std::endl;
    
    pthread_exit(NULL);

    std::cout << " main exit .this not run" << std::endl;
    return 0;
}
